<?php
 /*******************************************************************************
 * @filename: home.ctp
 *
 * @author: immer_baldos
 *
 * @description: root page
 *
 * @history:
 *
 *   VERSION   DATE                   BY          NOTES
 *  ---------------------------------------------------------------
 *     1.0     September  9, 2009     immer       initial bake
 *
 *     2.0     September 21, 2009     immer       add role based menus
 *
 ******************************************************************************/
    if (array_key_exists('Auth', $_SESSION)){
        if (array_key_exists('User', $_SESSION['Auth'])){
            //orders
            if ($_SESSION['Auth']['User']['role'] != "collectors" && $_SESSION['Auth']['User']['role'] != "product officer"){
                echo '<legend>'.$html->link('Order Online', '/orders/makeorder').'</legend>'.'<BR>';
            }
            //view orders
            if ($_SESSION['Auth']['User']['role'] != "collectors" && $_SESSION['Auth']['User']['role'] != "product officer"){
                echo '<legend>'.$html->link('View Orders', '/orders').'</legend>'.'<BR>';
            }
            //user management
            if ($_SESSION['Auth']['User']['role'] == "admin"){
                echo '<legend>'.$html->link('User Maintenance', '/users/index').'</legend>'.'<BR>';
            }

            //inventory management
            if ($_SESSION['Auth']['User']['role'] == "admin" || $_SESSION['Auth']['User']['role'] == "product officer"){
                echo '<legend>'.$html->link('Inventory Maintenance', '/products/index').'</legend>'.'<BR>';
            }

            //change password
            echo '<legend>'.$html->link('Change Password', ('/users/changepass/'.$_SESSION['Auth']['User']['id'])).'</legend>'.'<BR>';
        }else{
            echo $html->link('Please Login', '/users/login');
        }
    }else{
        echo $html->link('Please Login', '/users/login');
    }
    echo "<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>";
    echo "Seession INFORMATION:<BR>";
    print_r($_SESSION);
?>

<?php
if (Configure::read() > 0):
	Debugger::checkSessionKey();
endif;
?>
<p>
<?php
	if (is_writable(TMP)):
		echo '<span class="notice success">';
			__('Your tmp directory is writable.');
		echo '</span>';
	else:
		echo '<span class="notice">';
			__('Your tmp directory is NOT writable.');
		echo '</span>';
	endif;
?>
</p>
<p>
<?php
	$settings = Cache::settings();
	if (!empty($settings)):
		echo '<span class="notice success">';
				echo sprintf(__('The %s is being used for caching. To change the config edit APP/config/core.php ', true), '<em>'. $settings['engine'] . 'Engine</em>');
		echo '</span>';
	else:
		echo '<span class="notice">';
				__('Your cache is NOT working. Please check the settings in APP/config/core.php');
		echo '</span>';
	endif;
?>
</p>
<p>
<?php
	$filePresent = null;
	if (file_exists(CONFIGS . 'database.php')):
		echo '<span class="notice success">';
			__('Your database configuration file is present.');
			$filePresent = true;
		echo '</span>';
	else:
		echo '<span class="notice">';
			__('Your database configuration file is NOT present.');
			echo '<br/>';
			__('Rename config/database.php.default to config/database.php');
		echo '</span>';
	endif;
?>
</p>
<?php
if (!empty($filePresent)):
 	uses('model' . DS . 'connection_manager');
	$db = ConnectionManager::getInstance();
 	$connected = $db->getDataSource('default');
?>
<p>
<?php
	if ($connected->isConnected()):
		echo '<span class="notice success">';
 			__('Cake is able to connect to the database.');
		echo '</span>';
	else:
		echo '<span class="notice">';
			__('Cake is NOT able to connect to the database.');
		echo '</span>';
	endif;
?>
</p>
<?php endif;?>
<h3><?php __('Editing this Page') ?></h3>
<p>
<?php
	echo sprintf(__('To change the content of this page, edit: %s
		To change its layout, edit: %s
		You can also add some CSS styles for your pages at: %s', true),
		APP . 'views' . DS . 'pages' . DS . 'home.ctp.<br />',  APP . 'views' . DS . 'layouts' . DS . 'default.ctp.<br />', APP . 'webroot' . DS . 'css');
?>
</p>
